package com.hnisc.dao;

import com.hnisc.entity.Flighht;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 航班信息dao接口
 */
@Repository
public interface FlightDao {

   //根据航班编号查询航班记录数
   @Select("select  count(*) from flight where flightNo=#{flightNo}")
   Integer getFlightNo(@RequestParam("flightNo") String flightNo);

   //添加航班信息
   @Insert(value="INSERT INTO flight VALUES (null,#{flightNo},#{departureCity},#{departureTime},#{arrivalCity},#{arrivalTime})")
   Integer getAdd(Flighht flighht);

   //根据起飞城市id和到达城市id查询
   @Select("select a.id,flightNo,b.cityName,departureTime,c.cityName as cName,arrivalTime from flight a join city b on a.departureCity=b.id join city c on a.arrivalCity=c.id where a.departureCity=#{departureCity} and a.arrivalCity=#{arrivalCity} order by departureTime  asc")
   List<Flighht> getCity(@Param("departureCity") Integer departureCity,
                        @Param("arrivalCity") Integer arrivalCity);
}
